<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Document</title>
</head>
<body>
<input type="text" name="1" id="1">
<p id="2">名字：<span id="3"></span></p>
<button type="button" onclick="getNameByID()">接口测试</button>
</body>
<script>
    function getNameByID(){

        var xhr = new XMLHttpRequest();
        xhr.withCredentials = true;
        var URL = "http://localhost:8080/fourth_war/consumer/getNameByID.do" + "?id=" + document.getElementById('1').value;

        xhr.addEventListener("readystatechange", function() {
            if(this.readyState === 4) {
                console.log(this.responseText);
                document.getElementById('3').innerHTML = this.responseText;
            }
        });

        xhr.open("POST", URL );

        xhr.send();
    }
</script>
</html>